superstrict

import BRL.LinkedList
import BRL.Map

import "Datatype.bmx"

type Symbol

	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	const NONE:short = 0;
	const TRANSLATION_UNIT:short = 1;
	const DATABASE:short = 2;
	const TABLE:short = 3;
	const ROW:short = 4;
	const COLUMN:short = 5;
	const ASSIGNMENT:short = 6;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	function create:Symbol(name:string, symbtype:short, dtype:short = Datatype.DT_NONE, value:string = "")
	
		local symb:Symbol = new Symbol;
		
		symb.m_name = name;
		symb.m_type = symbtype;
		symb.m_datatype = dtype;
		symb.m_value = value;
		
		return symb;
	
	end function
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method push(sibling:Symbol)
	
		if (not sibling) ..
			return;
		
		sibling.m_parent = self;
		m_symbolList.addLast(sibling);
		m_symbolMap.insert(sibling.m_name, sibling);
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method pushColumn(sibling:Symbol)
	
		if (not sibling) ..
			return;
		
		sibling.m_parent = self;
		m_columnList.addLast(sibling);
		m_columnMap.insert(sibling.m_name, sibling);
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method find:Symbol(ident:string)
	
		if (not ident) ..
			return null;
		
		local symb:object = m_symbolMap.valueForKey(ident);
		
		if (symb) ..
			return Symbol(symb);
		
		return null;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method findColumn:Symbol(ident:string)
	
		if (not ident) ..
			return null;
		
		local symb:object = m_columnMap.valueForKey(ident);
		
		if (symb) ..
			return Symbol(symb);
		
		return null;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_parent:Symbol;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_name:string;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_type:short;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_datatype:short;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_value:string;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_columnList:TList = new TList;
	field m_columnMap:TMap = new TMap;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_symbolList:TList = new TList;
	field m_symbolMap:TMap = new TMap;

end type
